package com.mxpio.erp.common.oa.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.jpa.policy.ResCodeGeneratorPolicy;
import com.mxpioframework.filestorage.entity.MxpioFileInfo;
import com.mxpioframework.jpa.annotation.Generator;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.BaseEntity;
import com.mxpioframework.security.entity.Dept;
import com.mxpioframework.security.entity.Post;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "MB_ERP_OA_TRAVEL_REIMBURSEMENT")
@Schema(description="差旅报销单")
public class OaTravelReimbursement extends BaseEntity {


    @Id
    @Column(name = "BIZ_NO_", updatable = false)
    @Generator(policy = ResCodeGeneratorPolicy.class)
    @Schema(description = "差旅报销单编号")
    private String bizNo;

    @Column(name = "APPLY_ID_")
    @Schema(description = "申请人")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String applyId;

    /**申请时间*/
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd ")
    @Schema(description = "申请时间")
    @Column(name = "APPLY_TIME_")
    private Date applyTime;

    @Column(name = "REASON_",columnDefinition = "TEXT")
    @Schema(description = "事由")
    private String reason;

    @Column(name = "DUTIES_")
    @Schema(description = "职务")
    @Dict(dicCode = "id", dicEntity = Post.class, dicText = "name")
    private String duties;

    @Column(name = "CH_MONEY_")
    @Schema(description = "金额(大写)")
    private String chMoney;

    @Column(name = "ALL_MONEY_")
    @Schema(description = "总金额")
    private BigDecimal allMoney;


    @Column(name = "APPLY_USER_DEPT_ID_")
    @Schema(description = "申请部门")
    @Dict(dicCode = "deptCode", dicEntity = Dept.class, dicText = "deptName")
    private String applyUserDeptId;

    @Column(name = "SUBSIDY_CRITERIA_")
    @Schema(description = "补助标准")
    @Dict(dicCode = "MB_ERP_OA_TRAVEL_REIMBURSEMENT_SUBSIDY_CRITERIA")
    private String subsidyCriteria;

    /**审批状态*/
    @Column(name = "BPMN_STATUS_")
    @Schema(description = "审批状态")
    @Dict(dicCode = "ERP_COMMON_BPMN_STATUS")
    private String bpmnStatus;

    /**审批实例ID*/
    @Column(name = "PROCESS_INSTANCE_ID_")
    @Schema(description = "审批实例ID")
    private String processInstanceId;

    @Column(name = "FILE_NO_",columnDefinition = "TEXT")
    @Schema(description = "附件")
    @Dict(dicCode = "fileNo", dicEntity = MxpioFileInfo.class, dicText = "fileName")
    private String fileNo;

    /**审批记录*/
    @Column(name = "APPROVAL_RECORDS_", columnDefinition = "TEXT")
    @Schema(description = "审批记录")
    private String approvalRecords;

    @Column(name = "ORG_DESC_")
    @Schema(description = "一级部门描述")
    private String orgDesc;

    @Transient
    @Schema(description = "是否撤销审批")
    @Dict(dicCode = "ERP_COMMON_YESNO") //0否 1是
    private String revoke;

    @Column(name = "APPLICANTS_")
    @Schema(description = "申请单位")
    @Dict(dicCode = "MB_ERP_OA_REIMBURSEMENT_APPLICANTS")
    private String applicants;

    @Column(name = "APPLICANTS_ABBR_")
    @Schema(description = "申请单位(缩写)")
    private String applicantsAbbr;

    @Transient
    private List<OaTravelReimbursementLine> oaTravelReimbursementLine;
}
